
cc.Class({
    extends: cc.Component,

    properties: {
        actorScrollView:{
            default: null,
            type: cc.ScrollView
        },
        itemTemplate: {
            default: null,
            type: cc.Node
        },
        spacing: 20, // space between each item
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        //加载角色列表
        this.loadActorList();
    },

    start () {

    },

    update (dt) {},

    selectActor: function(){
        //选择角色
    },
    createActor: function(){
        //创建角色
    },
    //加载角色列表
    loadActorList: function(){
        this.actorScrollView.content.removeAllChildren();

        for(var i=0; i < 3; i++){
            let item = cc.instantiate(this.itemTemplate);
            let actorName = item.getChildByName('actorName');
            actorName.getComponent(cc.Label).string = "角色" + i;
            console.log(actorName);
            
            this.actorScrollView.content.addChild(item);
            item.setPosition(0, -(item.height * (0.5 + i) + this.spacing * (i + 1)));
        }
        this.actorScrollView.content.height = this.actorScrollView.content.childrenCount * (this.itemTemplate.height + this.spacing) + this.spacing;
        
    }

});
